<h1>Tous les matchs</h1>
<div class="title_w_bg">Liste des matchs joués</div>

<table class="scoreboard">
  <tr>
    <th>ID du match</th>
    <th>Compétiton</th>
    <th>Joueur 1</th>
    <th>Team 1</th>
    <th>Score</th>
    <th>Team 2</th>
    <th>Joueur 2</th>
    <th>Mode</th>
  </tr>
  <br>
  <% if @matches.count == 0 %>
    <tr> <td> Pas de match enregistré </td> </tr>
  <% else %>
    <% @matches.order('id DESC').each do |match| %>
      <% if match.teams.empty? %>
      <tr>
        <td><%= match.id %></td>
        <td>....</td>
        <td><%= link_to 'Supprimer', match_path(match), method: :delete,
                data: { confirm: 'Etes vous sur ?' }%></td>

      </tr>
      <% else %>
      <tr>
        <td><%= match.id %></td>
        <td><%= match.tournament.name %></td>
        <td><%= link_to Player.find(match.teams.first.player_id).pseudo, player_path(match.teams.first.player_id) %> </td>
        <td><%= match.teams.first.club.name %> </td>
        <td><div class="tab_score">
              <%= match.teams.first.score %> - <%= match.teams.last.score %>
            </div>
            <span class="tab_score_prol">
            <%= (match.prolongations && !match.teams.first.prol_score) ? "a.p" : "" %>
            <%= match.teams.first.prol_score %><%= match.teams.first.prol_score == nil ? '' : ' tab ' %><%= match.teams.last.prol_score %>
            </span>
        </td>

        <td><%= match.teams.last.club.name %> </td>
        <td><%= link_to Player.find(match.teams.last.player_id).pseudo, player_path(match.teams.last.player_id) %> </td>
        <td><%= match.mode%></td>
        <td><%= link_to "Détails", match_path(match)%></td>
        <% if user_signed_in? %>
          <td><%= link_to "Modifier", edit_match_path(match)%></td>
          <td><%= link_to 'Supprimer', match_path(match), method: :delete,
                  data: { confirm: 'Etes vous sur ?' }%></td>
        <% end %>
      </tr>
      <% end %>
    <% end %>
  <% end %>
</table>
<%== pagy_bootstrap_nav(@pagy) %>
